<?php

class Membership_model extends Model {

	function validate()
	{
		$this->db->where('login', $this->input->post('login'));
		$this->db->where('pwd', md5($this->input->post('pwd')));
		$query = $this->db->get('users');
		
		if($query->num_rows == 1)
		{
			return true;
		}	
	}
	
	function create_member()
	{
		
		$new_member_insert_data = array(
			'name' => $this->input->post('name'),
			'email' => $this->input->post('email'),		
			'login' => $this->input->post('login'),
			'pwd' => md5($this->input->post('pwd'))			
		);
		
		$insert = $this->db->insert('users', $new_member_insert_data);
		return $insert;
	}

	function taken_username($login)
	{
		$query_str = "SELECT login FROM users WHERE login = ?";
		$result = $this->db->query($query_str, $login);
		if ($result->num_rows() > 0)
		{
			//the login exists
			return true;
		}
		else
		{
			//username doesn't exists
			return false;
		}
	}

	function get_user_id($login)
	{
		$query_str = "SELECT id FROM users WHERE login = ?";
		$result = $this->db->query($query_str, $login);
		return $result;
	}
	
}
